<template>
  <div>
    <a-drawer :title="title" placement="right" :width="width" @close="onClose" :visible="visible">
      <div class="container">
        <a-form :form="form" @submit="handleSubmit">
          <a-form-item
            hasFeedback
            label="用户账号"
            :label-col="{ span: 5 }"
            :wrapper-col="{ span: 12 }"
          >
            <a-input
              v-decorator="[
          'account',
          {rules: [{ required: true, message: '请输入用户账号' }]}
        ]"
            />
          </a-form-item>
          <a-form-item
            hasFeedback
            label="用户名字"
            :label-col="{ span: 5 }"
            :wrapper-col="{ span: 12 }"
          >
            <a-input
              v-decorator="[
          'userName',
          {rules: [{ required: true, message: '请输入用户账号' }]}
        ]"
            />
          </a-form-item>
          <!-- <a-form-item label="角色分配" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
            <a-select
              mode="tags"
              style="width: 100%"
              v-decorator="[
          'role',
         ]"
              @change="RoleChange"
              placeholder="选择角色"
            >
              <a-select-option v-for="(item,index) in roleList" :key="String(index)">{{item.title}}</a-select-option>
            </a-select>
          </a-form-item> -->
          <a-form-item label="头像" :label-col="{ span: 5 }" :wrapper-col="{ span: 12}">
            <ant-avatar />
          </a-form-item>
          <a-form-item label="生日" :label-col="{ span: 5 }" :wrapper-col="{ span: 12}">
            <a-date-picker v-decorator="['birthday']" style="width:100%" />
          </a-form-item>
          <a-form-item label="性别" :label-col="{ span: 5 }" :wrapper-col="{ span: 12}">
            <a-select defaultValue="0" @change="onChange">
              <a-select-option value="0">男</a-select-option>
              <a-select-option value="1">女</a-select-option>
            </a-select>
          </a-form-item>
          <a-form-item hasFeedback label="邮箱" :label-col="{ span: 5 }" :wrapper-col="{ span: 12 }">
            <a-input
              v-decorator="[
          'email',
          {
             rules: [{
              type: 'email', message: '请输入正确的邮箱',
            }]
          }
        ]"
            />
          </a-form-item>
          <a-form-item
            hasFeedback
            label="手机号码"
            :label-col="{ span: 5 }"
            :wrapper-col="{ span: 12 }"
          >
            <a-input v-decorator="[
          'phone',
        ]" />
          </a-form-item>
          <a-form-item :wrapper-col="{ span: 12, offset: 5 }">
            <a-button type="primary" html-type="submit" icon="plus">添加</a-button>
          </a-form-item>
        </a-form>
      </div>
    </a-drawer>
  </div>
</template>
<script lang="ts">
import { Component, Vue, Prop, Emit, Watch } from "vue-property-decorator";

@Component({
  name: "sys-user-OpenDrawer",
  layout: "menu"
})
export default class OpenDrawer extends Vue {
  width: number = 600;
  form: any = {};
  sex: number = 0;
  handleOk() {}
  created() {
    this.$nextTick(() => {
      this.form = this.$form.createForm(this);
      if (this.title === "添加") {
        this.form.resetFields();
      }
    });
  }
  onChange(val) {
    this.sex = val;
  }
  handleSubmit(e) {
    e.preventDefault();
    this.form.validateFields((err, values) => {
      if (!err) {
        values.sex = this.sex;
        this.Submit(values);
      }
    });
  }
  @Prop({ type: String, required: false, default: "默认" }) title!: string;
  @Prop({ type: Boolean, required: true, default: false }) visible!: boolean;
  @Prop({ type: Array, required: true }) roleList!: any[];

  @Emit("onClose")
  onClose() {}
  @Emit("RoleChange")
  RoleChange(n: string) {}
  @Emit("Submit")
  Submit(n: object) {}
}
</script>
<style lang="less" scoped>
.container {
}
.formItem {
  display: flex;
  flex: 1;
  flex-direction: row;
  align-items: center;
}
</style>

